<template>
  <view class="container">
    <view class="top_k">
    	
    </view>
	<view class="top_yan">
		<image src="/static/images/icon-login.png" mode="widthFix"></image>
	</view>
	
	<view class="footer-sq">
		<view class="footer-bt"  @tap="gologin">
			<u-button type="primary" text="支付宝授权" :customStyle="{borderRadius:'30rpx'}"></u-button>
		</view>
		
		
		<view class="footer-test">
			申请获取你的公开信息 (昵称、头像等)
		</view>
	</view>
  </view>
</template>

<script>
import { zfbAuth} from "@/api/login/login";

const app = getApp();
export default {
  data() {
    return {
		timer:null,
      value: false,
      // 商城基本信息
      storeInfo: undefined,
      // 微信小程序登录凭证 (code)
      // 提交到后端，用于换取openid
      code: "",
	  form:{ 
		  v:'',
		  mobile:'',
		  password:'',
		  token:'',
		  },
		  serverpass:"",
      list: [
        {
          name: "注册",
          checked: false,
          disabled: false,
        },
      ],
	 rules: {
	  	// 字段名称
	  	mobile: [
	  		{
	  			required: true, 
	  			message: '请输入手机号',
	  			trigger: ['change','blur'],
	  		},
	  		{
	  			// 自定义验证函数，见上说明
	  			validator: (rule, value, callback) => {
	  				// 上面有说，返回true表示校验通过，返回false表示不通过
	  				// this.$u.test.mobile()就是返回true或者false的
	  				return this.$u.test.mobile(value);
	  			},
	  			message: '手机号码不正确',
	  			// 触发器可以同时用blur和change
	  			trigger: ['change','blur'],
	  		}
	  	],
	 	
	 		password: [
	 							{ 
	 								required: true, 
	 								message: '请输入密码', 
	 								// 可以单个或者同时写两个触发验证方式 
	 								trigger: ['change','blur'],
	 							}
	 						]
	 }	
    };
  },

  created() {},
  beforeDestroy() {
 //    console.log("返回了");
	// clearTimeout(this.timer)
 //    if (!uni.getStorageSync("userId")) {
 //      uni.removeStorageSync("userId");
 //      uni.removeStorageSync("mobile");
 //    }
  },
  onLoad() {
	  // var sjs=this.randomWord()
	  //     var datatime = Date.parse(new Date());
	  //     var tokens=''+sjs+''+datatime
	  // 		  this.form.token=tokens
	  // 		  this.form.v=uni.getStorageSync("v")
	  if(uni.getStorageSync("userId")){
		  if(!uni.getStorageSync("userMobile")){
		  						   uni.reLaunch({
		  						   	url:"/pages/empower/newpw"
		  						   })
		  }else{
		  		  this.handleCancel()
		  }
	  }
	 
  },
  // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
  	onReady() {
  	 		// this.$refs.uForm.setRules(this.rules);
  	 	},
		onShow() {
			 if (uni.getStorageSync("userId")&&uni.getStorageSync("userMobile")) {
				 
				 this.handleCancel()
			 }
			
		},
  methods: {
	 gologin(){
		  uni.getAuthCode({
		        scopes: 'auth_user',
		        success:  async res => {
		          const authCode = res.authCode;
				  console.log(res)
				  // return
		          // 在服务端获取用户信息
				 var res= await zfbAuth(JSON.stringify({code:authCode}) )
				 //  uni.setStorageSync("userId",res.user.id)
				 // uni.navigateTo({
				 // 	url:"/pages/empower/newpw"
				 // })
				 // return
				 if(res.result==0){
					 if (uni.getStorageSync("userId")) {
					 if(!res.user.userMobile){
					 						   uni.navigateTo({
					 						   	url:"/pages/empower/newpw"
					 						   })
					 }
				   }else{
					   uni.setStorageSync("userId",res.user.id)
					   if(!res.user.userMobile){
						   uni.navigateTo({
						   	url:"/pages/empower/newpw"
						   })
					   }else{
						   this.handleCancel()
					   }
					   uni.setStorageSync("userMobile",res.user.userMobile)
						
					   console.log(uni.getStorageSync("userId"))
				   }
				 }else{
					 this.$u.toast(res.message)
				 }
				 console.log(res)
		        },
		        fail: err => {
		          console.log('my.getAuthCode 调用失败', err)
		        }
		      });
	  },
	  handleCancel() {
		  // return
	   // if(getCurrentPages().length==1){
	   // 	wx.redirectTo({
	   // 	  url: '/pages/index/index'
	   // 	})
	   // }else{
	   	// 跳转回原页面
	   	uni.navigateBack({
	   	  delta: 1,
	   	});
	   // }
	  },
	   
  },
};
</script>

<style lang="scss" scoped>
	.container{
		width: 100%;
		height: 100vh;
		position: relative;
	}
.top_k{
	position: absolute;
	top: 312rpx;
	left: 0;
	width: 100%;
	height: 500rpx;
	// border-bottom: 250rpx solid rgba(255,255,255,0.1);
	// background-color: white;
	border-bottom-left-radius: 50%;
	border-bottom-right-radius: 50%;
	opacity: 1;
	box-shadow: 0 10px 20px 0px #C2C2C2;
	clip:rect(250rpx,800rpx,800rpx,0rpx);


}
.top_yan{
	position: absolute;
	top: 0;
	left: 0;
	width: 748rpx;
	height: 562rpx;
	background: linear-gradient(360deg, rgba(255,255,255,0.1) 3%, rgba(243,182,168,0.1) 16%, #EB5F3F 100%);
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	opacity: 1;
	text-align: center;
	image{
		width: 700rpx;
		z-index: 1;
		margin: 0 auto;
		margin-top: 360rpx;
	
	
	}
}

.footer-sq{
	position: absolute;
	left: 0;
	bottom: 94rpx;
	width: 100%;
	height: auto;
	text-align: center;
	.footer-bt{
		width: 490rpx;
		height: 81rpx;
		margin: 0 auto;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 42rpx;
		
		overflow: hidden;
	}
	.footer-test{
		margin-top: 68rpx;
		font-size: 23rpx;
		color: #606060;
		line-height: 32rpx;
	}
}


</style>
